package esay.array;

/**
 * 移除有序数组中的重复数字
 * @author ruizhou
 * @date 24.2.2018
 */
public class RemoveDuplicates4SortedArray {

    public static int removeDuplicates(int[] nums) {
        if (nums.length <= 0) {
            return 0;
        }

        int len = 1;
        for (int i = 1, size = nums.length; i < size; i++) {
            if (nums[i] != nums[i-1]) {
                nums[len] = nums[i];
                len++;
            }
        }
        return len;
    }

    public static void main(String[] args) {
        int[] nums = {1,1,2,2};
        System.out.println(removeDuplicates(nums));
    }
}
